1397C - Multiples of Length - CodeForces Solution


constructive algorithms greedy math number theory *1600

Please click on ads to support us..

C++ Code:

/*...Bismillahir Rahmanir Rahim...*/
// #pragma GCC optimize ("Ofast,unroll-loops")
// #pragma GCC target ("avx2")
#include <bits/stdc++.h>
using namespace std;

//debug..........
#ifdef Abdul_Aziz
#include "debug.cpp"
#else
#define dbg(x...)
#endif

#define   int  long long
#define   ll   long long
#define   ld   long double
#define   pb   push_back
#define   vi   vector<int>
#define   bitcount(x)  (int)__builtin_popcount(x)
#define   Lsb(x)  (int)__builtin_ctzll(x)
#define   fast  ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define   sz(x)  (int)x.size()
#define   all(a) (a).begin(),(a).end()
#define   Yes  cout << "YES\n"
#define   No  cout << "NO\n"
#define   ff   first
#define   ss   second
#define   endl  "\n"
#define   pi   acos(-1.0)
#define   pii  pair<int,int>
#define   lcm(a,b) (a/__gcd(a, b)*b)

const int  mod = 998244353 ;
const int N = 200005 ;
const int inf = 2147483647;

signed main()
{
    fast ;
    // cout << (-5%4) << endl;
    int n; cin >> n;
    vi a(n+1), rem(n, 0) ;
    for (int i=1;i<=n;++i) cin >> a[i] ;
    if (n==1) {
        cout << "1 1" << endl;
        cout << 0 << endl;
        cout << "1 1" << endl;
        cout << 0 << endl;
        cout << "1 1" << endl;
        cout << -a[1] << endl;
        return 0;
    }
    int cnt = 0;
    for (int i=n;1;i+=n) {
        int r = i%(n-1);
        if (!rem[r]) ++cnt;
        rem[r] = i;
        if (cnt==n-1) break;
    }
    cout << "1 " << n << endl;
    for (int i=1;i<=n;++i) {
        int r = ((n-1) - a[i]%(n-1))%(n-1) ;
        cout << rem[r] << " " ;
        a[i] += rem[r] ;
    }
    cout << endl;
    cout << "1 " << n-1 << endl;
    for (int i=1;i<n;++i) {
        cout << -a[i] << " ";
    }
    cout << endl;
    cout << n << " " << n << endl;
    cout << -a[n] << endl;
    return 0 ;
}


Comments

Submit
0 Comments
More Questions

230A - Dragons
200B - Drinks
13A - Numbers
129A - Cookies
1367B - Even Array
136A - Presents
1450A - Avoid Trygub
327A - Flipping Game
411A - Password Check
1520C - Not Adjacent Matrix
1538B - Friends and Candies
580A - Kefa and First Steps
1038B - Non-Coprime Partition
43A - Football
50A - Domino piling
479A - Expression
1480A - Yet Another String Game
1216C - White Sheet
1648A - Weird Sum
427A - Police Recruits
535A - Tavas and Nafas
581A - Vasya the Hipster
1537B - Bad Boy
1406B - Maximum Product
507B - Amr and Pins
379A - New Year Candles
1154A - Restoring Three Numbers
750A - New Year and Hurry
705A - Hulk
492B - Vanya and Lanterns